import java.util.Arrays;

public class Test {
    public static void main2(String[] args) {
        int[] array = {1,2,3,4} ;
        func1(array) ;
        for (int x:
             array) {
            System.out.print(x+ " ");
        }
        System.out.println();
        func2(array) ;
        for (int x:
                array) {
            System.out.print(x+" ");
        }
    }
    public static void func1(int[] array){
        array = new int[10] ;
    }
    public static void func2 (int[] array){
        array[0] = 99 ;
    }

    public static void main6(String[] args) {
        int[] array = {1,2,3,4} ;
        int[] copy  = new int[array.length ] ;
        System.arraycopy(array , 0 ,copy,2 ,2);
        System.out.println(Arrays.toString(copy));
    }
    public static void main5(String[] args) {
        int[] array = {1,2,3,4,5} ;
        int[] copy = Arrays.copyOfRange(array , 1 , 10) ;
        System.out.println(Arrays.toString(copy));

    }
    public static void main4(String[] args) {
        int[] array = {1,2,3,4} ;
        int[] copy = Arrays.copyOf(array ,array.length) ;
        int[] copy2 = Arrays.copyOf(array ,3) ;
        int[] copy3 = Arrays.copyOf(array ,array.length * 2) ;
        System.out.println(Arrays.toString(copy));
        System.out.println(Arrays.toString(copy2));
        System.out.println(Arrays.toString(copy3));



    }

    public static void main7(String[] args) {
        int[] array = { 22,3,1,5,33,7,8 } ;
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }

    public static void main(String[] args) {
         int[] arr = new int[10] ;
         Arrays .fill(arr , 2);
        System.out.println(Arrays.toString(arr));

    }
    public static void main8(String[] args) {
        int[] array = { 1,2,3,4,5 , 12 , 13 , 17} ;
//        System.out.println(binarySearch(array, 3));
        System.out.println(Arrays.binarySearch(array, 12));
    }
public static int binarySearch(int[] array , int key){
        int left = 0 ;
        int right = array.length - 1 ;
        while(left <= right){
            int mid = (left + right) / 2 ;
            if(array[mid] > key) {
                right = mid - 1 ;
            }else if(array[mid] < key){
                left = mid + 1 ;
            }else{
                return mid ;
            }
        }
    return -1 ;
}

    public static void main3(String[] args) {
      int[] array = {1} ;
        System.out.println(myToString(array));
    }
    public static String myToString(int[] array){
        if(array == null) return null ;
        String ret = "[" ;
        for (int i = 0; i < array.length; i++) {
            if(i != array.length - 1){
                ret += array[i] + "," ;
            }else {
                ret += array[i] ;
            }
        }
        ret += "]" ;
        return ret ;
    }


}
